import { IGeometry } from "../interface/geometry";

function geometryToGPUBuffer(device: GPUDevice, geometry: IGeometry){
    const buffer = {
        vertex: device.createBuffer({
            label: 'GPUBuffer store vertex',
            size: geometry.vertex.byteLength,
            usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
        }),
        index: device.createBuffer({
            
            size: geometry.index.byteLength,
            usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
        })
    }

    device.queue.writeBuffer(buffer.vertex, 0, geometry.vertex)
    device.queue.writeBuffer(buffer.index, 0, geometry.index)

    return buffer;
}

export { geometryToGPUBuffer }